<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Fairy:小程序</title>
</head>

<body>

<h1>数据库转移程序</h1>
<h6>同步表格的所有项目。</h6>
<? include_once "config.php"?>

<?
 



/*
1：设置源数据库
*/

	error_reporting(E_ERROR);
	define('CURSCRIPT', 'forumdisplay');
    $dbHostname = "localhost";
    $dbUsername = "root";
    $dbPassword = "98154981";
	$table_Prefix="athlon_";//该工程的table前缀
    $dbName= "erp_hengda";

    $dblink = MYSQL_CONNECT($dbHostname, $dbUsername, $dbPassword) OR DIE("数据库连接失败!");
    mysql_select_db($dbName) or die( "Unable to select database ".$dbName);
    mysql_query("set names utf8");


	
//需要同步的表格名称
echo $source_table=$table_Prefix."employee";

//获取字段信息，用于做同步插入
$root_source_full   =get_table_item_full($source_table);
$root_table_info_array= transform_2darray_in_1darray_with_new_key($root_source_full,"Field","Type");



mysql_close($con);






/*
2：设置需要增量同步的数据库2
*/

error_reporting(E_ERROR);
define('CURSCRIPT', 'forumdisplay');
$dbHostname2 = "localhost";
$dbUsername2 = "root";
$dbPassword2 = "98154981";
$table_Prefix2="athlon_";//该工程的table前缀
$dbName2= "oa";

$dblink2 = MYSQL_CONNECT($dbHostname, $dbUsername, $dbPassword) OR DIE("数据库连接失败!");
mysql_select_db($dbName2) or die( "Unable to select database ".$dbName2);
mysql_query("set names utf8");



//需要同步的表格名称
$target_table=$table_Prefix2."employee";

//获取字段信息，用于做同步插入
$target_source_full   =get_table_item_full($target_table);
$target_table_info_array= transform_2darray_in_1darray_with_new_key($target_source_full,"Field","Type");




mysql_close($con);




print_r2($root_table_info_array);
print_r2($target_table_info_array);



//源和目标对比，找出缺少的项目
$diff_itemlist=array_diff_key($root_table_info_array,$target_table_info_array);


print_r2($diff_itemlist);





foreach($diff_itemlist as $key=>$v) {

    $diff_itemlist_name[]=$key;
    $diff_itemlist_type[]=$v;
}





for($i=0;$i<count($diff_itemlist_name);$i++)
{

    echo $sql = "ALTER TABLE ".$target_table." ADD ".$diff_itemlist_name[$i]." ". $diff_itemlist_type[$i];
    echo "<br/>";

mysql_query($sql);
}




?>









</body>
</html>